import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import IconsResolver from 'unplugin-icons/resolver'
import path from "path";


// 根据 BUILD_ENV 设置不同的输出目录
const buildDir = process.env.BUILD_ENV === 'app' ? path.resolve(__dirname, "../main/app/build/web") : path.resolve(__dirname, "dist")
console.log("输出路径", buildDir)

// https://vite.dev/config/
export default defineConfig({
  server: {
    port: 5173,
    strictPort: true,
  },
  build:{
    emptyOutDir: true,
    outDir: buildDir,
  },
  base:"./",
  plugins: [
    // ...
    AutoImport({
      resolvers: [
        ElementPlusResolver() ,// Auto import icon components
        // 自动导入图标组件
        IconsResolver({
          prefix: 'Icon',
        }),
      ],
    }),
    Components({
      resolvers: [
        IconsResolver({
          enabledCollections: ['ep'],
        }),
        ElementPlusResolver()
      ],
    }),
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
